home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 22 / CU Amiga Magazine's Super CD-ROM 22 (1998)(EMAP Images)(GB)[!][issue 1998-05].iso / PowerPC / Programming / PPCSmallEiffel / lib_se / formal_arg_list.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  7.0 KB  |  326 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class FORMAL_ARG_LIST
  17.    --
  18.    -- For the formal arguments list of a routine.
  19.    --
  20.  
  21. inherit 
  22.    DECLARATION_LIST
  23.       rename make as standard_make
  24.       end;
  25.    
  26. creation {EIFFEL_PARSER} make
  27.    
  28. creation {DECLARATION_LIST} runnable_from_current
  29.    
  30. feature {NONE} -- Parsing creation procedure :
  31.    
  32.    make(sp: like start_position; l: like list) is
  33.       require
  34.      sp /= Void;
  35.      l.lower = 1;
  36.      not l.empty;
  37.       local
  38.      an: like name;
  39.      tlf: TYPE_LIKE_FEATURE;
  40.      tla, tla2: TYPE_LIKE_ARGUMENT;
  41.      i, rank: INTEGER;
  42.      an2: ARGUMENT_NAME2;
  43.       do
  44.      standard_make(sp,l);
  45.      -- Substitution TYPE_LIKE_FEATURE/TYPE_LIKE_ARGUMENT : 
  46.      from 
  47.         i := flat_list.upper;
  48.      until
  49.         i = 0
  50.      loop
  51.         an := flat_list.item(i);
  52.         tlf ?= an.result_type;
  53.         if tlf /= Void then
  54.            rank := rank_of(tlf.like_what.to_string);
  55.            if rank = i then
  56.           eh.add_position(tlf.start_position);
  57.           fatal_error(fz_cad);
  58.            elseif rank > 0 then
  59.           !!an2.refer_to(tlf.like_what.start_position,Current,rank);
  60.           !!tla.make(tlf.start_position,an2);
  61.           an.set_result_type(tla);
  62.            end;
  63.         end;
  64.         i := i - 1;
  65.      end;
  66.      if run_control.all_check then
  67.         from 
  68.            i := flat_list.upper;
  69.         until
  70.            i = 0
  71.         loop
  72.            tla ?= flat_list.item(i).result_type;
  73.            if tla /= Void then
  74.           rank := rank_of(tla.like_what.to_string);
  75.           tla2 ?= flat_list.item(rank).result_type;
  76.           if tla2 /= Void then
  77.              eh.add_position(tla.start_position);
  78.              eh.add_position(tla2.start_position);
  79.              fatal_error(fz_cad);
  80.           end;
  81.            end;
  82.            i := i - 1;
  83.         end;
  84.      end;
  85.       ensure
  86.      start_position = sp;
  87.      list = list
  88.      flat_list /= Void;
  89.       end;   
  90.    
  91. feature
  92.  
  93.    name(i: INTEGER): ARGUMENT_NAME1 is
  94.       do
  95.      Result := flat_list.item(i);
  96.       end;
  97.    
  98.    pretty_print is
  99.       local
  100.      i: INTEGER;
  101.       do
  102.      fmt.put_character('(');
  103.      fmt.level_incr;
  104.      from  
  105.         i := 1;
  106.      until
  107.         i > list.upper
  108.      loop
  109.         list.item(i).pretty_print;
  110.         i := i + 1;
  111.         if i <= list.upper then
  112.            fmt.put_string("; ");
  113.         end;
  114.      end;
  115.      fmt.level_decr;
  116.      fmt.put_character(')');
  117.       end;
  118.  
  119.    short is
  120.       local
  121.      i: INTEGER;
  122.       do
  123.      short_print.hook_or("hook302"," (");
  124.      from  
  125.         i := 1;
  126.      until
  127.         i > list.upper
  128.      loop
  129.         list.item(i).short;
  130.         i := i + 1;
  131.         if i <= list.upper then
  132.            short_print.hook_or("hook303"," ;");
  133.         end;
  134.      end;
  135.      short_print.hook_or("hook306",")");
  136.       end;
  137.    
  138.    compile_to_c_in(str: STRING) is
  139.       local
  140.      i: INTEGER;
  141.      t: TYPE;
  142.       do
  143.      from
  144.         i := 1;
  145.      until
  146.         i > count
  147.      loop
  148.         t := type(i).run_type;
  149.         t.c_type_for_argument_in(str);
  150.         str.extend(' ');
  151.         str.extend('a');
  152.         i.append_in(str);
  153.         i := i + 1;
  154.         if i <= count then
  155.            str.extend(',');
  156.         end;
  157.      end;
  158.       end;
  159.    
  160.    is_a_in(other: like Current; rc: RUN_CLASS): BOOLEAN is
  161.      -- True when `other' interpreted in `rc' is a kind of Current 
  162.      -- interpreted in `rc'.
  163.       require
  164.      other /= Void;
  165.      rc /= Void;
  166.       local
  167.      i: INTEGER;
  168.      t1, t2: TYPE;
  169.       do
  170.      if other.count /= count then
  171.         eh.add_position(other.start_position);
  172.         error(start_position,"Bad number of arguments.");
  173.      end;     
  174.      if nb_errors = 0 then
  175.         from  
  176.            Result := true;
  177.            i := 1;
  178.         until
  179.            not Result or else i > flat_list.upper
  180.         loop
  181.            t1 := type(i);
  182.            t2 := other.type(i);
  183.            if not t1.is_a_in(t2,rc) then
  184.           Result := false;
  185.           eh.print_as_error;
  186.           eh.add_position(t1.start_position);
  187.           eh.add_position(t2.start_position);
  188.           eh.append("Incompatible types in ");
  189.           eh.append(rc.current_type.run_time_mark);
  190.           eh.error(fz_dot);
  191.            end;
  192.            i := i + 1;
  193.         end;
  194.      end;     
  195.       end;
  196.  
  197. feature {JVM}
  198.  
  199.    jvm_switch_push(dyn_fal: like Current): INTEGER is
  200.      -- Push inside switching method.
  201.       require
  202.      count = dyn_fal.count
  203.       local
  204.      i: INTEGER;
  205.       do
  206.      from
  207.         i := 1;
  208.      until
  209.         i > count
  210.      loop
  211.         Result := Result + jvm_switch_push_ith(dyn_fal,i);
  212.         i := i + 1;
  213.      end;
  214.       end;
  215.  
  216.    jvm_switch_push_ith(dyn_fal: like Current; i: INTEGER): INTEGER is
  217.       local
  218.      t1, t2: TYPE;
  219.      offset: INTEGER;
  220.       do
  221.      offset := jvm.argument_offset_of(name(i));
  222.      t1 := type(i).run_type;
  223.      t2 := dyn_fal.type(i).run_type;
  224.      t1.jvm_push_local(offset);
  225.      Result := t1.jvm_convert_to(t2);
  226.  
  227. --***     if t1.is_reference then
  228. --***        if t2.is_reference then
  229. --***           -- Reference into reference :
  230. --***           Result := 1;
  231. --***        else
  232. --***           -- Reference into expanded :
  233. --***           Result := t1.jvm_to_expanded;
  234. --***        end;
  235. --***     elseif t2.is_expanded then
  236. --***        -- Expanded into expanded :
  237. --***        Result := t2.jvm_stack_space;
  238. --***     else
  239. --***        -- Expanded into reference :
  240. --***        Result := 1;
  241. --***     end;
  242.       end;
  243.  
  244. feature {RUN_FEATURE,SWITCH}
  245.  
  246.    jvm_descriptor_in(str: STRING) is
  247.       local
  248.      i: INTEGER;
  249.      at: TYPE;
  250.       do
  251.      from
  252.         i := 1;
  253.      until
  254.         i > count
  255.      loop
  256.         at := type(i).run_type;
  257.         if at.is_reference then
  258.            str.append(jvm_root_descriptor);
  259.         else
  260.            at.jvm_descriptor_in(str);
  261.         end;
  262.         i := i + 1;
  263.      end;
  264.       end;
  265.    
  266. feature {RUN_FEATURE_3}
  267.  
  268.    inline_one_pc is
  269.       local
  270.      i: INTEGER;
  271.      t: TYPE;
  272.       do
  273.      from
  274.         i := 1;
  275.      until
  276.         i > count
  277.      loop
  278.         t := type(i).run_type;
  279.         tmp_string.clear;
  280.         t.c_type_for_argument_in(tmp_string);
  281.         tmp_string.extend(' ');
  282.         cpp.put_string(tmp_string);
  283.         cpp.inline_level_incr;
  284.         cpp.print_argument(i);
  285.         cpp.inline_level_decr;
  286.         cpp.put_character('=');
  287.         cpp.put_ith_argument(i);
  288.         cpp.put_string(fz_00);
  289.         i := i + 1;
  290.      end;
  291.       end;
  292.  
  293. feature {RUN_FEATURE,CECIL_POOL}
  294.  
  295.    external_prototype(str: STRING) is
  296.       local
  297.      i: INTEGER;
  298.      t: TYPE;
  299.       do
  300.      from
  301.         i := 1;
  302.      until
  303.         i > count
  304.      loop
  305.         t := type(i).run_type;
  306.         t.c_type_for_external_in(str);
  307.         str.extend(' ');
  308.         str.extend('a');
  309.         i.append_in(str);
  310.         i := i + 1;
  311.         if i <= count then
  312.            str.extend(',');
  313.         end;
  314.      end;
  315.       end;
  316.  
  317. feature {NONE}
  318.  
  319.    tmp_string: STRING is
  320.       once
  321.      !!Result.make(32);
  322.       end;
  323.  
  324. end -- FORMAL_ARG_LIST
  325.  
  326.